'use strict';

/**
 * @description 租约信息表模型
 * */
module.exports = app => {
  const { DATE, INTEGER } = app.Sequelize;

  const Lease = app.model.define('lease', {
    startTime: {
      type: DATE,
      allowNull: false,
      comment: '开始时间',
    },
    endTime: {
      type: DATE,
      allowNull: false,
      comment: '结束时间',
    },
    uid: {
      type: INTEGER,
      allowNull: false,
      comment: '租客id',
    },
    houseId: {
      type: INTEGER,
      allowNull: false,
      comment: '房屋id',
    },
    status: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '状态 1-未生效 2-已生效 3-过期',
    },
  });

  Lease.associate = () => {
    app.model.Lease.belongsTo(app.model.House, {
      foreignKey: 'houseId',
    });
    app.model.Lease.belongsTo(app.model.User, {
      foreignKey: 'uid',
    });
  };

  return Lease;
};
